package com.heima.reggie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.reggie.domain.SetmealDish;
import com.heima.reggie.service.SetmealDishService;
import com.heima.reggie.mapper.SetmealDishMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* @author liulanhui
* @description 针对表【setmeal_dish(套餐菜品关系)】的数据库操作Service实现
* @createDate 2023-01-04 21:57:43
*/
@Service
@Slf4j
public class SetmealDishServiceImpl extends ServiceImpl<SetmealDishMapper, SetmealDish>
    implements SetmealDishService{
    @Autowired
    SetmealDishMapper setmealDishMapper;

    @Override
    public List<SetmealDish> selectAllBySetmealId(Long setmealId) {
        String idStr = Long.toString(setmealId);
        List<SetmealDish> setmealDishes = setmealDishMapper.selectAllBySetmealId(idStr);
        return setmealDishes;
    }

    @Override
    public void deleteBySetmealId(Long dishId) {
        String idStr = Long.toString(dishId);
        setmealDishMapper.deleteBySetmealId(idStr);
    }

    @Override
    public void deleteBySetmealIdIn(Long[] setmealId) {

        String idStr = Arrays.toString(setmealId);
        log.info("str={}",idStr);
        String substring = idStr.substring(1, idStr.length() - 1);
        log.info("str={}",substring);
        String[] split = substring.split(",");
        log.info("split={}",split);
        for(int i = 0; i < split.length;++i) {
            List<String> longs = Collections.singletonList(split[i]);
            log.info("longs={}", longs);
            setmealDishMapper.deleteBySetmealIdIn(longs);
        }
    }
}




